package com.situ.day2;

import org.junit.Test;

public class TypeDemo {


    // 当行注释 Ctrl+/
    // 多行注释 Ctrl+Shift+/
    /*数据类型转换：
    1、从小到大自动类型转换
    2、从大到小需要强制类型转换，可能会丢失精度(装水的杯子大小不一样)
    byte->short(char)->int->long->float->double*/
    @Test
    public void testNum() {
        //双目运算符
        //单目运算符 ++ --
        byte num1 = 23;
        int num2 = num1;
        char ch1 = 'a';
        int num3 = ch1;//97
        System.out.println(num3);

        double num4 = 3.14;
        int num5 = (int)num4;
        System.out.println(num5);//3

        int num6 = 128;
        byte num7 = (byte) num6;
    }

    @Test
    public void test2() {
        int num1 = 3;
        int num2 = 5;
        int result1 = num1 + num2;
        System.out.println(result1);
        int result2 = num1 - num2;
        System.out.println(result2);
        System.out.println(num1 * num2);
        System.out.println(num1 / num2);//0
        System.out.println(num1 % num2);//3

        System.out.println("-----------");
        System.out.println(8 / 2);//4
        System.out.println(8 % 2);//0
        System.out.println(8 / 5);//1
        System.out.println(8 % 5);//3
    }


    @Test
    public void test4() {
        // ++(自增1)    --(自减1)
        int i = 0;
        // i = i + 1;
        i++;// i = i + 1;
        ++i;// i = i + 1;
        i--;// i = i - 1;
        --i;// i = i - 1;

        //1、单独使用的时候，++、--在前后是没有差别的
        //2、被使用的时候，在前后是有差别的:
        // ++放在右边：先用后加
        // ++放在左边：先加后用
        int j = 1;
        System.out.println(j++);//1  j:2
        System.out.println(++j);//3  j:3
    }

    @Test
    public void  test6() {
        int num1 = 3;
        int num2 = 5;
        boolean b1 = num1 < num2;
        System.out.println(b1);//true

        // <= 小于或者等于
        boolean b2 = num1 <= num2;
        System.out.println(b2);//true

    }

    @Test
    public void test11() {
        boolean b1 = true;
        System.out.println(!b1);//false
        boolean b2 = !b1;
        System.out.println(b2);//false
    }

    @Test
    public void test44() {
        int score1 = 67;
        int score2 = 389;
        boolean result1 = (score1 >= 60) && (score2 >= 400);
        System.out.println(result1);//false
        // () && ()     () || ()
        boolean result2 = (score1 >= 60) || (score2 >= 400);
        System.out.println(result2);//true
    }

    @Test
    public void test55() {
        int num1 = 3;
        int num2 = 5;
        //&&短路
        System.out.println(num1 < 0 && num1++ < num2);//false
        System.out.println(num1);//3  4
        System.out.println(num2);//5  5
        //||短路
        System.out.println(num1 > 0 || num1++ < num2);//true
        System.out.println(num1);//3  5
        System.out.println(num2);//5  5
    }

}
